import 'package:flutter/material.dart';
import '../models/sleep_data_model.dart';

/// 睡眠追踪卡片主题配置
class SleepTrackingTheme {
  // 颜色配置
  final Map<SleepStage, Color> stageColors;
  final Color cardBackgroundStart;
  final Color cardBackgroundEnd;
  final Color tooltipBackground;
  final Color textPrimary;
  final Color textSecondary;
  final Color borderColor;

  // 尺寸配置
  final double cardWidth;
  final double cardPadding;
  final double cardBorderRadius;
  final double barWidth;
  final double barSpacing;
  final double chartHeight;
  final double pieChartRadius;
  final double pieChartCenterRadius;

  // 字体配置
  final TextStyle tooltipTextStyle;
  final TextStyle timeTextStyle;
  final TextStyle labelTextStyle;
  final TextStyle statLabelStyle;
  final TextStyle statValueStyle;

  const SleepTrackingTheme({
    // 颜色
    this.stageColors = const {
      SleepStage.deep: Color(0xFF1E3A8A),
      SleepStage.light: Color(0xFF3B82F6),
      SleepStage.rem: Color(0xFF06B6D4),
      SleepStage.awake: Color(0xFFE5E7EB),
    },
    this.cardBackgroundStart = const Color(0xFF2D2D2D),
    this.cardBackgroundEnd = const Color(0xFF1F1F1F),
    this.tooltipBackground = const Color(0x99000000),
    this.textPrimary = Colors.white,
    this.textSecondary = const Color(0xFF9CA3AF),
    this.borderColor = const Color(0x33FFFFFF),

    // 尺寸
    this.cardWidth = 380,
    this.cardPadding = 24,
    this.cardBorderRadius = 24,
    this.barWidth = 28,
    this.barSpacing = 5,
    this.chartHeight = 180,
    this.pieChartRadius = 24,
    this.pieChartCenterRadius = 32,

    // 字体
    this.tooltipTextStyle = const TextStyle(
      color: Colors.white,
      fontSize: 14,
      fontWeight: FontWeight.w600,
      letterSpacing: 0.5,
    ),
    this.timeTextStyle = const TextStyle(
      color: Colors.white,
      fontSize: 22,
      fontWeight: FontWeight.bold,
      letterSpacing: 0.5,
    ),
    this.labelTextStyle = const TextStyle(
      color: Color(0xFF9CA3AF),
      fontSize: 14,
      fontWeight: FontWeight.w500,
    ),
    this.statLabelStyle = const TextStyle(
      color: Color(0xFF9CA3AF),
      fontSize: 13,
      fontWeight: FontWeight.w500,
    ),
    this.statValueStyle = const TextStyle(
      color: Colors.white,
      fontSize: 18,
      fontWeight: FontWeight.bold,
      letterSpacing: 0.3,
    ),
  });

  /// 获取睡眠阶段颜色
  Color getStageColor(SleepStage stage) {
    return stageColors[stage] ?? Colors.grey;
  }

  /// 获取睡眠阶段渐变
  LinearGradient getStageGradient(SleepStage stage, {bool isActive = false}) {
    final baseColor = getStageColor(stage);
    final activeIntensity = stage == SleepStage.awake ? 0.2 : 0.15;
    
    return LinearGradient(
      begin: Alignment.bottomCenter,
      end: Alignment.topCenter,
      colors: [
        Color.lerp(baseColor, Colors.white, isActive ? activeIntensity : 0.0)!,
        Color.lerp(_getDarkerShade(baseColor), Colors.white, isActive ? activeIntensity : 0.0)!,
      ],
      stops: const [0.0, 1.0],
    );
  }

  /// 获取更深的色调
  Color _getDarkerShade(Color color) {
    final hsl = HSLColor.fromColor(color);
    return hsl.withLightness((hsl.lightness - 0.1).clamp(0.0, 1.0)).toColor();
  }

  /// 创建亮色主题
  static SleepTrackingTheme light() {
    return const SleepTrackingTheme(
      cardBackgroundStart: Color(0xFFF8F9FA),
      cardBackgroundEnd: Color(0xFFE9ECEF),
      tooltipBackground: Color(0xCC000000),
      textPrimary: Color(0xFF212529),
      textSecondary: Color(0xFF6C757D),
      borderColor: Color(0x1A000000),
      tooltipTextStyle: TextStyle(
        color: Colors.white,
        fontSize: 14,
        fontWeight: FontWeight.w600,
        letterSpacing: 0.5,
      ),
      timeTextStyle: TextStyle(
        color: Color(0xFF212529),
        fontSize: 22,
        fontWeight: FontWeight.bold,
        letterSpacing: 0.5,
      ),
      labelTextStyle: TextStyle(
        color: Color(0xFF6C757D),
        fontSize: 14,
        fontWeight: FontWeight.w500,
      ),
      statLabelStyle: TextStyle(
        color: Color(0xFF6C757D),
        fontSize: 13,
        fontWeight: FontWeight.w500,
      ),
      statValueStyle: TextStyle(
        color: Color(0xFF212529),
        fontSize: 18,
        fontWeight: FontWeight.bold,
        letterSpacing: 0.3,
      ),
    );
  }

  /// 创建紧凑主题
  static SleepTrackingTheme compact() {
    return const SleepTrackingTheme(
      cardWidth: 320,
      cardPadding: 16,
      cardBorderRadius: 16,
      barWidth: 24,
      chartHeight: 150,
      pieChartRadius: 20,
      pieChartCenterRadius: 28,
      tooltipTextStyle: TextStyle(
        color: Colors.white,
        fontSize: 12,
        fontWeight: FontWeight.w600,
        letterSpacing: 0.3,
      ),
      timeTextStyle: TextStyle(
        color: Colors.white,
        fontSize: 18,
        fontWeight: FontWeight.bold,
        letterSpacing: 0.3,
      ),
      statValueStyle: TextStyle(
        color: Colors.white,
        fontSize: 16,
        fontWeight: FontWeight.bold,
        letterSpacing: 0.2,
      ),
    );
  }
} 